package com.gs.djys.checkfragments.soliciting;


import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bumptech.glide.util.Util;
import com.gs.djys.Base.MyAppliCation;
import com.gs.djys.R;
import com.gs.djys.Util.NoScroolGridView;
import com.gs.djys.Util.ShowGridAdapter;
import com.gs.djys.Util.ToastUtils;
import com.gs.djys.Util.Utils;
import com.gs.djys.check.checklistitem.CheckListItemActivity;
import com.gs.djys.land.LandBean;
import com.gs.djys.mvp.MVPBaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class SolicitingFragment extends MVPBaseFragment<SolicitingContract.View, SolicitingPresenter> implements SolicitingContract.View {
    @Bind(R.id.sjgj_list)
    NoScroolGridView sjgjList;
    @Bind(R.id.sglj_list)
    NoScroolGridView sgljList;
    @Bind(R.id.sggj_list)
    NoScroolGridView sggjList;
    @Bind(R.id.activity_disease_detail_scrollview)
    ScrollView activityDiseaseDetailScrollview;
    @Bind(R.id.sjgj_sj)
    TextView sjgjSj;
    @Bind(R.id.sjgj_sljg)
    TextView sjgjSljg;
    @Bind(R.id.sjgj_zqyj)
    TextView sjgjZqyj;
    @Bind(R.id.sglj_sj)
    TextView sgljSj;
    @Bind(R.id.sglj_sljg)
    TextView sgljSljg;
    @Bind(R.id.sglj_zqyj)
    TextView sgljZqyj;
    @Bind(R.id.sggj_sj)
    TextView sggjSj;
    @Bind(R.id.sggj_sljg)
    TextView sggjSljg;
    @Bind(R.id.sggj_zqyj)
    TextView sggjZqyj;


    @Override
    public void onRequestError(String msg) {
        ToastUtils.showShortToast(msg);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fra_soliciting, container, false);
        ButterKnife.bind(this, view);
        initview();
        return view;
    }

    private void initview() {
        mPresenter.getYJ(MyAppliCation.spUtils.getString("REQ_NO"));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @Override
    public void getYJs(SolicitingBean landBeans) {
        if (landBeans != null) {
            if (landBeans.getData().getRecords().size() > 0) {
                List<SolicitingBean.DataBean.RecordsBean> landBean = landBeans.getData().getRecords();
                for (int i = 0; i < landBean.size(); i++) {
                    if (landBean.get(i).getTYPE().equals("sjgj")) {
                        sjgjSj.setText("时间：" + landBean.get(i).getCON_TIME());
                        sjgjSljg.setText("受理结果：" + landBean.get(i).getIS_AGREE());
                        sjgjZqyj.setText("征求意见：" + landBean.get(i).getRESULT());
                        if (!Utils.isNull(landBean.get(i).getFILE_ID())) {
                            ArrayList<String> listImgUrl1 = new ArrayList<>();
                            String[] strArr = landBean.get(i).getFILE_ID().split(",");
                            if (strArr != null && strArr.length > 0) {
                                for (int j = 0; j < strArr.length; j++) {
                                    listImgUrl1.add(strArr[j]);
                                }
                            }
                            ShowGridAdapter ShowGridAdapter1 = new ShowGridAdapter(getContext(), listImgUrl1);
                            sjgjList.setAdapter(ShowGridAdapter1);
                        }
                    } else if (landBean.get(i).getTYPE().equals("sglj")) {
                        sgljSj.setText("时间：" + landBean.get(i).getCON_TIME());
                        sgljSljg.setText("受理结果：" + landBean.get(i).getIS_AGREE());
                        sgljZqyj.setText("征求意见：" + landBean.get(i).getRESULT());
                        if (!Utils.isNull(landBean.get(i).getFILE_ID())) {
                            ArrayList<String> listImgUrl1 = new ArrayList<>();
                            String[] strArr = landBean.get(i).getFILE_ID().split(",");
                            if (strArr != null && strArr.length > 0) {
                                for (int j = 0; j < strArr.length; j++) {
                                    listImgUrl1.add(strArr[j]);
                                }
                            }
                            ShowGridAdapter ShowGridAdapter1 = new ShowGridAdapter(getContext(), listImgUrl1);
                            sgljList.setAdapter(ShowGridAdapter1);
                        }
                    } else if (landBean.get(i).getTYPE().equals("sggj")) {
                        sggjSj.setText("时间：" + landBean.get(i).getCON_TIME());
                        sggjSljg.setText("受理结果：" + landBean.get(i).getIS_AGREE());
                        sggjZqyj.setText("征求意见：" + landBean.get(i).getRESULT());
                        if (!Utils.isNull(landBean.get(i).getFILE_ID())) {
                            ArrayList<String> listImgUrl1 = new ArrayList<>();
                            String[] strArr = landBean.get(i).getFILE_ID().split(",");
                            if (strArr != null && strArr.length > 0) {
                                for (int j = 0; j < strArr.length; j++) {
                                    listImgUrl1.add(strArr[j]);
                                }
                            }
                            ShowGridAdapter ShowGridAdapter1 = new ShowGridAdapter(getContext(), listImgUrl1);
                            sggjList.setAdapter(ShowGridAdapter1);
                        }
                    }
                }
            }
        }
    }
}
